from django.shortcuts import render,redirect
from .models import *
# Create your views here.
def lst(request):
    if request.method=='GET':
        data=Stu.objects.all()
        return render(request,'lst.html',{'data':data})
    name=request.POST.get('name')
    age=request.POST.get('age')
    Stu.objects.create(name=name,age=age)
    return redirect('/app01/lst/')
def dele(request):
    nid=request.GET.get('nid')
    Stu.objects.filter(id=nid).delete()
    return redirect('/app01/lst/')
def edit(request):
    nid = request.GET.get('nid')
    if request.method=='GET':
        obj=Stu.objects.filter(id=nid).first()
        return render(request,'edit.html',{'obj':obj})
    name=request.POST.get('name')
    age=request.POST.get('age')
    Stu.objects.filter(id=nid).update(name=name,age=age)
    return redirect('/app01/lst/')